package me.qixiaobo.util;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.annotation.JsonView;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import me.qixiaobo.config.JsonViewConfig;

import java.io.Serializable;

@Data
@ApiModel(value = "ResultModel对象", description = "接口响应对象，主要包含状态码、响应信息以及响应内容")
public class ResultModel<T> implements Serializable {
    @ApiModelProperty(value = "状态码", name = "code", example = "200")
    private int status;

    @ApiModelProperty(value = "响应信息", name = "message", example = "success")
    private String message;

    @ApiModelProperty(value = "响应内容", name = "data", dataType = "Object")
    @JsonView(JsonViewConfig.INormalView.class)
    private T data;

    public ResultModel(ResultStatusEnum rse) {
        this.status = rse.getStatus();
        this.message = rse.getMessage();
        this.data = null;
    }

    public ResultModel(ResultStatusEnum rse, T data) {
        this.status = rse.getStatus();
        this.message = rse.getMessage();
        this.data = data;
    }

    public ResultModel(int status, String message) {
        this.status = status;
        this.message = message;
    }

    public ResultModel(int status, String message, T data) {
        this.status = status;
        this.message = message;
        this.data = data;
    }

    public ResultModel() {
    }
}
